#include "login.h"
#include <main.h>


SOCKET      send_client;
SOCKET      receive_client;
sockaddr_in ssin;
sockaddr_in rsin;
MsgThread   *msgthread;
void Destory();

int main(int argc, char *argv[])
{
    qRegisterMetaType<string>("string");
    QApplication a(argc, argv);




    if (Init())
    {
        QMessageBox::information(nullptr, "connection", "connection success");

        msgthread = new MsgThread(receive_client);
        msgthread->start();
        Login w;
        w.show();
        a.exec();
        Destory();
        return 0;
    }else {
        QMessageBox::information(nullptr, "connection", "connection falie");
        return 0;
//        Login w;
//        w.show();
    }


    a.exec();
    return 0;
}

bool Init(){
    SockInit();
    char kServerIPAddress[20] = "127.0.0.1";
    return (SockCreatConnection(kServerPort, kServerIPAddress, send_client, ssin)
            && SockCreatConnection(kServerPort, kServerIPAddress, receive_client, rsin));

}

void Destory(){
        SockClose(send_client);
        SockClose(receive_client);
        SockDestory();
        delete msgthread;
}
